﻿using System;
using System.Collections.Generic;
using System.Text;

/*
 * Balances : Represent fixed fund Balances over time;  Balances may be historical (real) or volatile (projections)
 *              Historical Balances are persisted via xml serialization whereas volatile projections are calculated 
 *              at run-time (fitting projections to adhere to any historical balance points)
 * 
 * Transactions : Derive from Balances, used typically with relative amounts rather than balances, and include 
 *                  a reference to the affecting actor for use in analysis such as fund disbural charting
 */

namespace ContinuumSL.Classes
{
    public enum BalanceTypeEnum { HistoricalBalance, VolatileBalance, VolatileTransaction, InceptionBalance };

    public class Balance
    {
        private Decimal _Amount;
        public Decimal Amount { get { return _Amount; } set { _Amount = value; } }

        private DateTime _BalanceDate;
        public DateTime BalanceDate { get { return _BalanceDate; } set { _BalanceDate = value; } }

        private string _Description;
        public string Description { get { return _Description; } set { _Description = value; } }

        public BalanceTypeEnum Type;    // Only persisting Historical so no need for property accessor to serialize

        public Balance()
        {
        }

        public Balance(Decimal Amount, DateTime BalanceDate, string Description)
        {
            this.Amount = Amount;
            this.BalanceDate = BalanceDate;
            this.Description = Description;
        }

        public override string ToString()
        {
            return BalanceDate.ToShortDateString() + ";" + Amount.ToString() + ";" + Description;
        }
    }

    class BalanceComparer : IComparer<Balance>
    {

        public int Compare(Balance balance1, Balance balance2)
        {
            return balance1.BalanceDate.CompareTo(balance2.BalanceDate);
        }

    }

    class BalanceDescendingComparer : IComparer<Balance>
    {

        public int Compare(Balance balance1, Balance balance2)
        {
            return balance2.BalanceDate.CompareTo(balance1.BalanceDate);
        }

    }

    public class Transaction : Balance 
    {
        public Actor AffectingActor;

        public Transaction () : base ()
        {
        }

        public Transaction(Decimal Amount, DateTime BalanceDate, string Description, Actor AffectingActor)
            : base(Amount, BalanceDate, Description)
        {
            this.AffectingActor = AffectingActor;
        }
    }

    class TransactionComparer : IComparer<Transaction>
    {

        public int Compare(Transaction balance1, Transaction balance2)
        {
            return balance1.BalanceDate.CompareTo(balance2.BalanceDate);
        }

    }

    class TransactionDescendingComparer : IComparer<Transaction>
    {

        public int Compare(Transaction balance1, Transaction balance2)
        {
            return balance2.BalanceDate.CompareTo(balance1.BalanceDate);
        }

    }

}
